
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:syn_4s/core/extension/build_context_extension.dart';
import 'package:syn_4s/core/extension/int_extension.dart';
import 'package:syn_4s/ui/widgets/shadow_container.dart';
import '../../core/viewmodel/setting_view_model.dart';
import 'gradient_button.dart';

class CheckUpdateDialog extends StatelessWidget {
  // const CheckUpdateDialog({Key? key}) : super(key: key);
  final SettingViewModel viewModel = Get.find<SettingViewModel>();
  CheckUpdateDialog({super.key});

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      child: Dialog(
        child: ShadowContainer(
            width: 300.px,
            padding: EdgeInsets.all(8.px),
            child: buildDialogContent(context)
        ),
      ),
    );
  }

  Widget buildDialogContent(BuildContext context){
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        GestureDetector(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                SvgPicture.asset("assets/images/map_icon_close.svg",width: 24.px,height: 24.px,)
              ],
            ),
            onTap: ()=> Navigator.pop(context)
        ),
        Padding(
          padding: EdgeInsets.all(10.px),
          child: Column(
            children: [
              SizedBox(height: 10.px),
              Text(context.l10n.update_tips, style: TextStyle(fontSize: 20.px, color: Colors.grey)),
              SizedBox(height: 5.px),
              Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Text(context.l10n.new_version+"${viewModel.versionModel.value.versionNumber.toString()}", style: TextStyle(fontSize: 16.px, color: Colors.black)),
                ],
              ),
              SizedBox(height: 5.px),
              Row(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Expanded(
                      child: Text("${viewModel.versionModel.value.releaseNotes.toString()}",
                          style: TextStyle(fontSize: 16.px, color: Colors.black)
                      )
                  )
                ],
              ),
              SizedBox(height: 20.px),
              buildButton(context)
            ],
          ),
        )
      ],
    );
  }

  Widget buildButton(BuildContext context) {
    return GradientButton(
      onPressed: () {
        viewModel.downloadApk();
      },
      child: Text(
        context.l10n.update_now,
        style: TextStyle(color: Colors.white, fontSize: 20.px),
      )
    );
  }
  
}
